package com.ruoyi.baseData.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.ruoyi.baseData.domain.*;
import com.ruoyi.baseData.domain.ProceduresTeam;
import com.ruoyi.baseData.domain.dto.ProceduresEquipmentConfigDto;
import com.ruoyi.baseData.domain.dto.ProceduresTeamDto;
import com.ruoyi.baseData.domain.dto.WoProceduresDto;
import com.ruoyi.baseData.domain.vo.ProceduresEquipmentConfigVo;
import com.ruoyi.baseData.domain.vo.ProceduresTeamVo;
import com.ruoyi.baseData.domain.vo.ProceduresTeamVo;
import com.ruoyi.baseData.domain.vo.WoProceduresVo;
import com.ruoyi.baseData.mapper.ProceduresTeamMapper;
import com.ruoyi.baseData.service.ProceduresTeamService;
import com.ruoyi.baseData.mapper.ProceduresTeamMapper;
import com.ruoyi.common.core.utils.bean.BeanUtils;
import com.ruoyi.common.core.utils.sql.QueryHelp;
import com.ruoyi.common.security.utils.SecurityUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 *
 */
@Service
public class ProceduresTeamServiceImpl implements ProceduresTeamService{
    @Resource
    ProceduresTeamMapper proceduresTeamMapper;
    @Override
    public Page<ProceduresTeamVo> getProceduresTeamByPage(ProceduresTeamDto pageEntity) {
        MPJLambdaWrapper<ProceduresTeam> wrapper = new MPJLambdaWrapper<ProceduresTeam>()
                .selectAll(ProceduresTeam.class)//查询user表全部字段
                .selectAs( Procedures::getName, ProceduresTeamVo::getProceduresName )
                .selectAs( Team::getName, ProceduresTeamVo::getTeamName)
                //记的测试阶段
                .eq(ProceduresTeam::getDelFlag, 0)
                .eq(ProceduresTeam::getProceduresId, pageEntity.getProceduresId())
                .leftJoin(Procedures.class, Procedures::getId, ProceduresTeam::getProceduresId)
                .leftJoin(Team.class, Team::getId, ProceduresTeam::getTeamId)
                .orderByDesc(ProceduresTeam::getCreateTime);
        wrapper = QueryHelp.getPredicateEx(wrapper, ProceduresTeam.class, pageEntity);
        Page<ProceduresTeamVo> userList = proceduresTeamMapper.selectJoinPage(new Page<>(pageEntity.getCurrentPage(), pageEntity.getPageSize()),   ProceduresTeamVo.class, wrapper);
        return userList;
    }

    @Override
    public void addProceduresTeams(List<ProceduresTeamDto> proceduresTeamDtos) {
        String userName = SecurityUtils.getUsername();
        for(ProceduresTeamDto proceduresTeamDto : proceduresTeamDtos) {
            ProceduresTeam proceduresEquipmentConfig = new ProceduresTeam();
            BeanUtils.copyProperties(proceduresTeamDto, proceduresEquipmentConfig, new String[]{"id"});
            proceduresEquipmentConfig.setDelFlag(false);
            proceduresEquipmentConfig.setCreateBy(userName);
            proceduresEquipmentConfig.setCreateTime(new Date());
            proceduresTeamMapper.insert(proceduresEquipmentConfig);
        }
    }

    @Override
    public void addProceduresTeam(ProceduresTeamDto proceduresTeamDto) {
        String userName = SecurityUtils.getUsername();
        ProceduresTeam proceduresEquipmentConfig = new ProceduresTeam();
        BeanUtils.copyProperties(proceduresTeamDto, proceduresEquipmentConfig, new String[]{"id"});
        proceduresEquipmentConfig.setDelFlag(false);
        proceduresEquipmentConfig.setCreateBy(userName);
        proceduresEquipmentConfig.setCreateTime(new Date());
        proceduresTeamMapper.insert(proceduresEquipmentConfig);

    }

    @Override
    public WoProceduresVo getTeamAndProceduresByWo(WoProceduresDto materialDto) {
        return null;
    }


}




